<template>
	<view class="main">
		<view class="header">
			<text class="title">通行二维码</text>
		</view>
		<view class="content">
			<view class="qrcode-box">
				<uv-qrcode ref="qrcodeRef" canvas-id="qrcode" :value="value" size="300rpx"></uv-qrcode>
			</view>
			<text class="description">提供二维码以作通行证</text>
		</view>
		<view class="footer">
			<button class="btn-refresh" @click="refreshQRCode">刷新二维码</button>
		</view>
	</view>
</template>

<script setup>
	import uvQrcode from '@/uni_modules/uv-qrcode/components/uv-qrcode/uv-qrcode.vue';
	import {
		onMounted,
		ref
	} from 'vue';

	const value = 'https://www.baidu.com';
	const qrcodeRef = ref(null);

	const refreshQRCode = () => {
		qrcodeRef.value?.remake({
			success: () => {
				console.log('二维码已刷新');
			},
			fail: (err) => {
				console.log('二维码生成失败', err);
			},
		});
	};

	onMounted(() => {
		refreshQRCode();
	});
</script>

<style lang="less">
	.main {
		min-height: 85vh;
		background: linear-gradient(135deg, #f6f9fc, #eef2f3);
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		align-items: center;
		padding: 4vw;
	}

	.header {
		width: 100%;
		text-align: center;
		margin-bottom: 20px;
	}

	.title {
		font-size: 36rpx;
		font-weight: bold;
		color: #333;
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.qrcode-box {
		background: #fff;
		padding: 20rpx;
		border-radius: 20rpx;
		box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
	}

	.description {
		margin-top: 16rpx;
		font-size: 28rpx;
		color: #666;
	}

	.footer {
		width: 100%;
		display: flex;
		justify-content: center;
	}

	.btn-refresh {
		background: #0084ff;
		color: #fff;
		font-size: 30rpx;
		padding: 16rpx 40rpx;
		border-radius: 8rpx;
		box-shadow: 0 4px 10px rgba(0, 132, 255, 0.4);
	}
</style>